<template>
  <div class="learn-report">
    <div v-if="!showHistory && lessonsData.studentId">
      <div class="lesson-info-container">
        <img src="/src/assets/myStudent/lesson-icon.png" alt />
        <div class="lesson-info">
          <div class="lesson-title">
            <span>{{lessonsTopData.indexName || lessonsTopData.child.name}}</span>
            <span>上课时间: {{lessonsTopData.classTime}}</span>
            <div class="history-btn" @click="queryHistory">
              所有课次
              <i class="el-icon-d-arrow-right"></i>
            </div>
          </div>
          <div class="lesson-key-point">
            <div>重难点:</div>
            {{lessonsTopData.difficultPoint}}
          </div>
          <div class="lesson-key-point">
            <div>知识点:</div>
            {{filterKnowledge}}
          </div>
        </div>
      </div>
      <div class="performance-info">
        <div class="score-count-container">
          <div class="score-count">
            <span class="count-title">进门考</span>
            <div class="count-content">
              <div class="count-score">
                {{lessonsData.entranceScore || 0}}
                <span>分</span>
              </div>
              <div class="count-compare">
                <div>
                  平均分
                  <span
                    :class="{'is_down' : lessonsData.avgEntranceScore < 0}"
                  >{{lessonsData.avgEntranceScore || 0}}</span>
                </div>
                <div>
                  较上节课
                  <span
                    :class="{'is_down' : lessonsData.moreEntranceScore < 0}"
                  >{{lessonsData.moreEntranceScore || 0}}</span>
                </div>
              </div>
            </div>
          </div>
          <div class="score-count">
            <span class="count-title">讲义练习</span>
            <div class="count-content">
              <div class="count-score">
                {{lessonsData.practiceScore || 0}}
                <span>分</span>
              </div>
              <div class="count-compare">
                <div>
                  平均分
                  <span
                    :class="{'is_down' : lessonsData.avgPracticeScore < 0}"
                  >{{lessonsData.avgPracticeScore || 0}}</span>
                </div>
                <div>
                  较上节课
                  <span
                    :class="{'is_down' : lessonsData.morePracticeScore < 0}"
                  >{{lessonsData.morePracticeScore || 0}}</span>
                </div>
              </div>
            </div>
          </div>
          <div class="score-count">
            <span class="count-title">上节课作业</span>
            <div class="count-content">
              <div class="count-score">
                {{lessonsData.lastHomeworkScore || 0}}
                <span>分</span>
              </div>
              <div class="count-compare">
                <div>
                  平均分
                  <span
                    :class="{'is_down' : lessonsData.avgHomeworkScore < 0}"
                  >{{lessonsData.avgHomeworkScore}}</span>
                </div>
                <div>
                  较上节课
                  <span
                    :class="{'is_down' : lessonsData.moreHomeworkScore < 0}"
                  >{{lessonsData.moreHomeworkScore}}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="wrong-topic-count">
          <div class="wrong-topic">
            <span>本节课错题数</span>
            <div>
              <span>{{lessonsData.currentCount || 0}}</span>道
            </div>
          </div>
          <div class="wrong-topic">
            <span>累计错题数</span>
            <div>
              <span>{{lessonsData.wrongTopicTotal||0}}</span>道
            </div>
          </div>
        </div>

        <div class="lesson-summary">
          <div class="container-title">课堂小结</div>
          <div class="container-content">
            <div class="lesson-comment-container">
              <div class="lesson-comment-item">
                <div style="width: 12px; height: 12px; background: #72b22a;"></div>
                <span class="comment-label">出勤情况:</span>
                <span
                  class="comment-value"
                >{{['提前到', '准时', '迟到', '缺勤'][lessonsData.attendance - 1] || '' }}</span>
              </div>
              <div class="lesson-comment-item">
                <div style="width: 12px; height: 12px; background: #FF6B69;"></div>
                <span class="comment-label">听课状态:</span>
                <span
                  class="comment-value"
                >{{['优秀', '良好', '一般'][lessonsData.listenState - 1] || '' }}</span>
              </div>
              <div class="lesson-comment-item">
                <div style="width: 12px; height: 12px; background: #F9BB41;"></div>
                <span class="comment-label">上节课作业:</span>
                <span
                  class="comment-value"
                >{{['完成', '部分完成', '未完成'][lessonsData.lastHomework - 1] || '' }}</span>
              </div>
              <div class="lesson-comment-item">
                <div style="width: 12px; height: 12px; background: #949AED;"></div>
                <span class="comment-label">出门清:</span>
                <span class="comment-value">{{['优秀', '良好', '一般'][lessonsData.outState - 1] || '' }}</span>
              </div>
            </div>
            <div class="container-footer"></div>
          </div>
        </div>

        <div class="personality-comment">
          <div class="container-title">个性点评</div>
          <div class="container-content">
            <div class="container-input" v-html="lessonsData.comment"></div>
            <div class="container-footer"></div>
          </div>
        </div>
      </div>
    </div>
    <HistoryLesson v-else-if="showHistory && lessonsData.studentId" :list="historyLessons" />
    <div class="no-data" v-else>
      <div>当前学生还没有评价信息，备课完成后，请在第三步评价学生后查看。</div>
      <img src="/src/assets/myStudent/no-learn-report.png" alt />
    </div>
  </div>
</template>

<script lang='ts'>
import HistoryLesson from './components/history-lesson.vue'
import { ref, watch, computed } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
import $ from '$'
export default {
  components: { HistoryLesson },
  props: {
    studentId: String,
    data: {
      type: Object,
      default: {},
    },
    searchType: {
      type: Number,
      default: '',
    },
  },
  setup(props) {
    let showHistory = ref(false)
    let filterKnowledge = computed(() => {
      const child: any = lessonsTopData.value.child
      if (!child) return ''
      return child.childs && child.childs.length > 0
        ? child.childs.map((e) => e.name).join(',')
        : ''
    })
    let lessonsData = ref({
      attendance: '' /** 出勤情况 */,
      listenState: '' /** 听课状态 */,
      lastHomework: '' /** 上节课作业 */,
      outState: '' /** 出门清 */,
      entranceScore: '' /** 进门考得分 */,
      practiceScore: '' /** 讲义联系得分 */,
      lastHomeworkScore: '' /** 上节课作业得分 */,
      wrongTopicTotal: '' /** 错题总数 */,
      comment: '' /** 评语 */,
      moreEntranceScore: '' /** 比上节课进门考得分 */,
      avgEntranceScore: '' /** 进门考平均得分 */,
      morePracticeScore: '' /** 比上节课讲义练习得分 */,
      avgPracticeScore: '' /** 讲义练习平均得分 */,
      moreHomeworkScore: '' /** 比上节课作业得分 */,
      avgHomeworkScore: '' /** 作业平均得分 */,
      currentCount: '' /** 本节课错题 */,
    })
    let lessonsTopData = ref({ child: {} })
    let historyLessons = ref([])
    const getLastLesson = async () => {
      if (!props.studentId) return
      let lessonRes = await $.http.post('/admin/lessonSummary/queryLast', {
        status: 1,
        searchType: props.searchType,
        orderType: 1,
        studentId: props.studentId,
      })
      lessonRes.result && (lessonsData.value = lessonRes.json)
      !lessonRes.result && ElMessage.error(lessonRes.msg)
      if (!lessonRes.json.lessonThirdId) return
      let topRes = await $.http.post(
        '/admin/lessonTimes/queryLessonInfoForStudent',
        {
          lessonId: props.data.type ? props.data.lessonId : props.data.contractId,
          lessonThirdId: lessonRes.json.lessonThirdId,
        }
      )
      if (!topRes.result) return ElMessage.error(topRes.msg)
      lessonsTopData.value = topRes.json
    }
    getLastLesson()
    const queryHistory = async () => {
      showHistory.value = true
      let res = await $.http.post(
        '/admin/lessonSummary/querySummaryByStudentId',
        {
          status: 1,
          searchType: props.searchType,
          orderType: 1,
          studentId: props.studentId,
        }
      )
      historyLessons.value = res.json
    }
    return {
      showHistory,
      getLastLesson,
      lessonsData,
      lessonsTopData,
      filterKnowledge,
      queryHistory,
      historyLessons,
    }
  },
}
</script>

<style scoped lang="scss">
.learn-report {
  height: calc(100% - 60px);
  background: #f4f5f9;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  .lesson-info-container {
    padding: 25px 30px;
    background: #ffffff;
    box-shadow: 0px 1px 6px 0px rgba(91, 125, 255, 0.08);
    border-radius: 0 0 6px 6px;
    border: 1px solid #ebf0fc;
    display: flex;
    > img {
      height: 60px;
      width: 60px;
      margin-right: 15px;
    }
    .lesson-info {
      flex: 1;
      :nth-child(2) {
        margin: 10px 0;
      }
      .lesson-title {
        display: inline-block;
        width: 100%;
        align-items: center;
        :nth-child(1) {
          font-size: 20px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333333;
        }
        :nth-child(2) {
          font-size: 16px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #999999;
          margin-left: 15px;
        }
        .history-btn {
          float: right;
          padding: 7px 24px;
          background: rgba(250, 173, 20, 0.8);
          border-radius: 18px;
          font-size: 14px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #ffffff;
          cursor: pointer;
          > i {
            &::before {
              font-size: 14px;
              font-weight: 500;
              color: #fff;
            }
          }
        }
      }
      .lesson-key-point {
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
        display: flex;
        > div {
          position: relative;
          margin-right: 10px;
          &::before {
            content: '';
            height: 50%;
            background-color: #fbbd42;
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            opacity: 0.4;
          }
        }
      }
    }
  }
  .performance-info {
    flex: 1;
    margin-top: 20px;
    background: #ffffff;
    box-shadow: 0px 1px 6px 0px rgba(91, 125, 255, 0.08);
    border-radius: 6px;
    border: 1px solid #ebf0fc;
    position: relative;
    padding: 30px;
    &::before {
      content: '';
      width: 270px;
      height: 16px;
      background: #72b22a;
      border-radius: 8px;
      position: absolute;
      left: calc(50% - 135px);
      top: -8px;
    }
  }
  .score-count-container {
    display: grid;
    grid-template: auto / repeat(3, calc((100% - 72px) / 3));
    grid-gap: 36px;
    .score-count {
      background: #f5f9fd;
      border-radius: 6px;
      padding: 15px 50px 15px 30px;
      .count-title {
        font-size: 16px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #999999;
      }
      .count-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .count-score {
          font-size: 38px;
          font-weight: 400;
          color: #333333;
          > span {
            font-family: PingFangSC-Regular, PingFang SC;
            font-size: 14px;
          }
        }
        .count-compare {
          > div {
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
            text-align: right;
            > span {
              font-size: 14px;
              font-family: PingFangSC-Medium, PingFang SC;
              font-weight: 500;
              color: #72b22a;
              margin-left: 8px;
            }
            .is_down {
              color: #fa5f1d;
            }
          }
        }
      }
    }
  }
  .wrong-topic-count {
    display: grid;
    grid-template: auto / repeat(2, calc((100% - 26px) / 2));
    grid-gap: 36px;
    margin-top: 15px;
    .wrong-topic {
      background: #f5f9fd;
      border-radius: 6px;
      padding: 18px 30px;
      align-items: center;
      display: flex;
      > span {
        font-size: 16px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #999999;
      }
      > div {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
        margin-left: 25px;
        > span {
          font-size: 38px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #333333;
          margin-right: 5px;
        }
      }
    }
  }

  .lesson-summary {
    margin: 30px 0;
    .container-title {
      background: #ffefeb;
    }
    .container-content {
      padding: 10px 30px 32px 30px;
    }
  }
  .personality-comment {
    .container-title {
      background: #fef7e8;
    }
  }
  .container-title {
    border-radius: 10px 10px 0px 0px;
    border: 1px solid #dee4f1;
    font-size: 18px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    padding: 5px 20px;
    display: inline-block;
    border-bottom: none;
  }
  .container-content {
    min-height: 163px;
    position: relative;
    border-radius: 0px 10px 10px 10px;
    border: 1px solid #dee4f1;
    .container-input {
      height: 100%;
      padding: 22px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #333333;
    }
    .lesson-comment-container {
      height: calc(100% - 22px);
      display: grid;
      grid-gap: 1px;
      background: #dee4f1;
      grid-template: repeat(2, calc((100% - 1px) / 2)) / 40% calc(60% - 1px);
      .lesson-comment-item {
        background: #ffffff;
        display: flex;
        align-items: center;
        padding: 20px;
        .comment-label {
          margin: 0 20px 0 10px;
          min-width: 80px;
          font-size: 14px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #666666;
        }
        .comment-value {
          font-size: 18px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333333;
          min-width: 80px;
        }
      }
      & > :nth-child(2n) {
        padding-left: 100px;
      }
    }
    .container-footer {
      height: 22px;
      background: rgba(56, 42, 116, 0.07);
      border-radius: 0px 0px 10px 10px;
      border: 1px solid #ebf0fc;
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
    }
  }
}
.no-data {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  background: #fff;
  > div {
    width: 534px;
    height: 66px;
    font-size: 24px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    line-height: 33px;
    text-align: center;
  }
  > img {
    width: 232px;
    height: 195px;
    margin-top: 55px;
  }
}
</style>
